package router

import (
	"XSSS_v2/handler/admin"
	"XSSS_v2/handler/student"
	"XSSS_v2/router/middleware"
	"github.com/gin-gonic/gin"
	gs "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
)

func SetupRouter() *gin.Engine {
	r := gin.Default()

	r.GET("/swagger/*any", gs.WrapHandler(swaggerFiles.Handler))

	r.POST("/register", admin.Register)
	r.POST("/login", admin.Login)

	a := r.Group("/v1/admin")
	a.Use(middleware.AuthLogin())
	a.Use(middleware.PermissionMiddleWare())
	{
		a.POST("", student.CreateStu)
		a.DELETE("/:id", student.DeleteStu)
		a.PUT("/:id", student.UpdateStu)
		a.GET("", student.ListAllStu)
		a.GET("/:sno", student.GetAStu)
	}
	return r
}
